<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="/layui/jquery-3.5.1.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
</head>
<body>
    <form class="layui-form" action="">

        <input type="hidden" name="modelid" id="modelid" th:value="${id}"/>

        <div class="layui-form-item">
            <label class="layui-form-label">内容文件</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="submitForm"   type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">提交风险</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置内容</button>
            </div>
        </div>
    </form>
</body>
<script th:inline="javascript">
    layui.use(['jquery','form', 'upload', 'element'], function(){
        var form = layui.form
            ,element = layui.element
            ,layer = layui.layer
            ,$ = layui.jquery
            ,upload = layui.upload;

        form.on('submit(demo1)', function(data){

            return false;
        });
        upload.render({
            elem: '#test8'
            ,url: '/purchase/addModelRisk' //改成您自己的上传接口
            ,auto: false
            ,accept:'file'
            ,exts:'zip|rar|7z'
            ,bindAction: '#submitForm'
            ,acceptMime:'file/zip,file/rar,file/7z'
            ,data:{}
            ,before:function () {
                this.data.id = $("#modelid").val();
            }
            ,done: function(res){

                if (res.msg == "yes"){
                    layer.msg("上传成功")
                    var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index1); //再执行关闭
                }

                 //再执行关闭
                //window.location = '/purchase/';
            }
            ,error:function (res) {
                if (res.msg == "yes"){
                    layer.msg("上传成功")
                }
            }

        });
    });
</script>
</html>